package com.eling.elcms.travel.webapp.controller;

import com.eling.elcms.core.dao.hibernate.search.SearchCondition;
import com.eling.elcms.core.webapp.controller.BaseFormController;
import com.eling.elcms.core.webapp.controller.Msg;
import com.eling.elcms.core.webapp.spring.ModelFilling;
import com.eling.elcms.travel.model.ProductType;
import com.eling.elcms.travel.service.IProductTypeManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
public class ProductTypeController extends BaseFormController{

	@Autowired
	private IProductTypeManager typeManager;
	
	@RequestMapping("/api/producttype/save")
    @ResponseBody
	public ProductType save(@ModelAttribute@ModelFilling ProductType productType){
		return typeManager.save(productType);
	}
	
	@RequestMapping("/api/producttype/{pkProductType}/delete")
	@ResponseBody
	public Msg delete(@PathVariable Long pkProductType){
		typeManager.remove(pkProductType);
		return new Msg("删除成功");
	}
	
	@RequestMapping("/api/producttype/query")
    @ResponseBody
	public List<ProductType> query(@ModelAttribute ProductType productType){
		return typeManager.query(productType);
	}

	@RequestMapping("/api/producttype/search*")
	@ResponseBody
	public List<ProductType> search(@ModelAttribute SearchCondition sc,@ModelAttribute ProductType productType){
		sc.setQueryCondition(productType);
		return typeManager.search(sc);
	}
	
	/**
	 * 意向登记根据产品查询产品类型
	 * @param productType
	 * @return
	 */
	@RequestMapping("/api/producttype/querytype")
	@ResponseBody
	public List<ProductType> queryType(@RequestParam(name = "pkProduct", required = false)Long pkProduct){
		return typeManager.queryType(pkProduct);
	}

	@RequestMapping("/api/producttype/changeseal")
	@ResponseBody
	public ProductType changeseal(@ModelAttribute ProductType productType){
		return typeManager.changeseal(productType);
	}
	
	@RequestMapping("/api/producttype/savetype")
    @ResponseBody
	public ProductType savetype(@ModelAttribute@ModelFilling ProductType productType){
		return typeManager.savetype(productType);
	}//自定义保存方法

	@RequestMapping("/api/producttype/seekquote")
    @ResponseBody
	public boolean seekquote(@RequestParam(value ="pkProductType",required = false) Long pkProductType){
		return typeManager.seekquote(pkProductType);
	}//引用状态查询
}
